﻿var dsGListCreateTransferInput;
var rowselectGListCreateTransferInput;
var countGListCreateTransferInput = 500;
var selectCboFilterUnitKerjaCreateTransferInput;
var rowselectGridDetailEntryCreateTransferInput;
var now = new Date();
var winFormEntryCreateTransferInput;
var dsGridDetailEntryCreateTransferInput;
var CurrentRowGridDetailEntryCreateTransferInput = {
	data: Object,
	details: Array,
	row: 0
};
var selectcboStoreFromCreateTransferInput;
var vAddNewDataEntryCreateTransferInput;
var akun;
var jumlah;
var mRecordDetailEntryCreateTransferInput = Ext.data.Record.create(
	[
		{ NAME: 'TAHUN_ANGGARAN_TA', mapping: 'TAHUN_ANGGARAN_TA' },
		{ NAME: 'KD_UNIT_KERJA', mapping: 'KD_UNIT_KERJA' },
		{ NAME: 'KD_JNS_RKAT_JRKA', mapping: 'KD_JNS_RKAT_JRKA' },
		{ NAME: 'NO_PROGRAM_PROG', mapping: 'NO_PROGRAM_PROG' },
		{ NAME: 'PRIORITAS', mapping: 'PRIORITAS' },
		{ NAME: 'NO_SP3D', mapping: 'NO_SP3D' },
		{ NAME: 'TGL_SP3D', mapping: 'TGL_SP3D' },
		{ NAME: 'LINE', mapping: 'LINE' },
		{ NAME: 'ACCOUNT', mapping: 'ACCOUNT' },
		{ NAME: 'NAME', mapping: 'NAME' },
		{ NAME: 'DESKRIPSI', mapping: 'DESKRIPSI' },
		{ NAME: 'VALUE', mapping: 'VALUE' },
		{ NAME: 'POSTED', mapping: 'POSTED' },
		{ NAME: 'DESKRIPSI', mapping: 'DESKRIPSI' }
	]
);
var dtTglSP3DAsal;

CurrentPage.page = getPnlEntryCreateTransferInput(CurrentPage.id);
mainPage.add(CurrentPage.page);
mainPage.setActiveTab(CurrentPage.id);

function getPnlEntryCreateTransferInput(mod_id)
{
	var Fields = 
	[
		'NO_SP3D',
		'TGL_SP3D',
		'TAHUN_ANGGARAN_TA',
		'KD_UNIT_KERJA',
		'KD_JNS_RKAT_JRKA',
		'NO_PROGRAM_PROG',
		'PRIORITAS',
		'NAMA_PROGRAM_PROG',
		'KEGIATAN',
		'RKAT',
		'UNITKERJA',
		'KETERANGAN',
		'JUMLAH',
		'APP_SP3D',
		'APP_LEVEL_1',
		'APP_LEVEL_2',
		'APP_LEVEL_3',
		'APP_LEVEL_4',
		'IS_JALUR',
		'JML_ANGGARAN'
	];
	dsGListCreateTransferInput = new WebApp.DataStore({ fields: Fields });
	
	// var chkApprovedCreateTransferInput = new Ext.grid.CheckColumn(
		// {
			// id: 'N',
			// header: 'Approved',
			// align: 'center',			
			// dataIndex: 'APP_SP3D',
			// disabled: true,
			// readOnly: true,
			// width: 80
		// }
	// );
	
	var grdListCreateTransferInput = new Ext.grid.EditorGridPanel(
		{
			id: 'grdListCreateTransferInput',
			anchor: '100% 100%',
			width: 720,
			border: false,
			columnLines: true,
			store: dsGListCreateTransferInput,
			sm: new Ext.grid.RowSelectionModel(
				{
					singleSelect: true,
					listeners:
					{
						'rowselect': function(sm, row, rec)
						{
							rowselectGListCreateTransferInput = dsGListCreateTransferInput.getAt(row);
						}
					}
				}
			),
//			plugins: chkApprovedCreateTransferInput,
			cm: new Ext.grid.ColumnModel(
				[
					new Ext.grid.RowNumberer(),
					{
						xtype: 'gridcolumn',
						header: 'Nomor Transfer',
						dataIndex: 'NO_SP3D',
						width: 150,
						renderer: function(v, params, record)
						{
							var str = "<div style='white-space:normal; padding: 2px;'>" + record.data.NO_SP3D + "</div>";
							return str;
						}
					},
					{
						xtype: 'gridcolumn',
						header: 'Tanggal',
						dataIndex: 'TGL_SP3D',
						width: 80,
						readOnly:true,
						renderer: function(v, params, record)
						{
							var str = "<div style='white-space:normal; padding: 2px;'>" + record.data.TGL_SP3D + "</div>";
							return str;
						}
					},
					{
						xtype: 'gridcolumn',
						header: 'Unit Kerja',
						dataIndex: 'UNITKERJA',
						width: 120,
						renderer: function(v, params, record)
						{
							var str = "<div style='white-space:normal; padding: 2px;'>" + record.data.UNITKERJA + "</div>";
							return str;
						}
					},
					{
						xtype: 'gridcolumn',
						header: 'Keperluan',
						dataIndex: 'KETERANGAN',
						width: 180,
						renderer: function(v, params, record)
						{
							var str = "<div style='white-space:normal; padding: 2px;'>" + record.data.KETERANGAN + "</div>";
							return str;
						}
					},
					{
						xtype: 'gridcolumn',
						header: 'Jumlah',
						dataIndex: 'JUMLAH',
						width: 90,
						renderer: function(v, params, record)
						{
							var str = "<div style='white-space:normal; padding: 2px;text-align: right;'>" + formatCurrency(record.data.JUMLAH) + "</div>";
							return str;
						}
					}
					//,
//					chkApprovedCreateTransferInput
				]
			),
			tbar:
			[
				{
					xtype: 'button',
					id: 'btnEditCreateTransferInput',
					iconCls: '',
					text: 'Edit Data',
					handler: function()
					{
						if(rowselectGListCreateTransferInput !== undefined)
						{
							showWinFormEntryCreateTransferInput(rowselectGListCreateTransferInput.data);
						}
						else
						{
							showWinFormEntryCreateTransferInput();
						}
					}
				},
				{ xtype: 'tbseparator' }
			],
			
			listeners:
			{
				'afterrender': function(){ RefreshDataGListCreateTransferInput(getCriteriaGListCreateTransferInput()); }
			}
		}
	);
	
	var pnlCreateTransferInput = new Ext.Panel(
		{
			id: mod_id,
			region: 'center',
			layout: 'form',
			title: 'Create Transfer',          
			border: false,  
			closable: true,
			iconCls: '',
			margins: '0 5 5 0',
			items: [grdListCreateTransferInput],
			tbar:
			[
				{ xtype: 'tbtext', text: 'Nomor : ', cls: 'left-label', width: 45 },
				{
					xtype: 'textfield',
					id: 'txtFilterNoCreateTransferInput',
					width: 120
				},
				{ xtype: 'tbseparator' },
				//{ xtype: 'tbtext', text: 'Unit Kerja : ', cls: 'left-label', width: 60 },
//				mCboFilterUnitKerjaCreateTransferInput(),
				//{ xtype: 'tbseparator' },
				// {
					// xtype: 'checkbox',
					// id: 'chkFilterApprovedCreateTransferInput',
					// boxLabel: 'Approved'
				// },
				{ xtype: 'tbfill' },
				{
					xtype: 'button',
					id: 'btnRefreshCreateTransferInput',
					iconCls: 'refresh',
					handler: function()
					{
						RefreshDataGListCreateTransferInput(getCriteriaGListCreateTransferInput());
					}
				}
			]
		}
	);
	
	return pnlCreateTransferInput;
}


function RefreshDataGListCreateTransferInput(criteria)
{
	dsGListCreateTransferInput.load
	(
		{ 
			params: 
			{ 
				Skip: 0, 
				Take: countGListCreateTransferInput, 
				Sort: '', 
				Sortdir: 'ASC', 
				target: 'viSP3D',
				param: criteria
			} 
		}
	);
	
	return dsGListCreateTransferInput;
}

function getCriteriaGListCreateTransferInput()
{
	var strKriteria = "";
	
	if(Ext.getCmp('txtFilterNoCreateTransferInput').getValue() != "")
	{
		if(strKriteria != "")
		{
			strKriteria += "&";
		}
		strKriteria += "no=" + Ext.getCmp('txtFilterNoCreateTransferInput').getValue();
	}
	
	if(selectCboFilterUnitKerjaCreateTransferInput !== undefined)
	{
		if(strKriteria != "")
		{
			strKriteria += "&";
		}
		strKriteria += "unit=" + selectCboFilterUnitKerjaCreateTransferInput;
	}
	

	
	return strKriteria;
}

function showWinFormEntryCreateTransferInput(rowdata)
{
	// var pnlTotDetailJumEntryCreateTransferInput = new Ext.Panel
	// (
		// {
			// id: 'pnlTotDetailJumEntryCreateTransferInput',
			// layout: 'hbox',
			// border: false,	
			// region: 'south',
			// height: 107,
			// bodyStyle: 'padding: 10px 18px 0 10px;border-top: solid 1px #DFE8F6;',
			// defaults:
			// {
				// flex: 1
			// },
			// items:
			// [
				// {
					// xtype: 'panel',
					// layout: 'form',
					// border: false,
					// width: 400,
					// defaults: { anchor: '100%', readOnly: true },
					// items:
					// [
						// { 
							// xtype: 'checkboxgroup',
							// id: 'cgApprovedEntryCreateTransferInput',					
							// fieldLabel: 'Telah disahkan oleh',
							// itemCls: 'x-check-group-alt',	
							// disabled: true,
							// readOnly: true,							
							// columns: 4,
							// items: 
							// [
								// {boxLabel: 'Unit Kerja', id: 'chkAppKajurEntryCreateTransferInput', NAME: 'chkAppKajurEntryCreateTransferInput'},						
								// {boxLabel: 'Fakultas', id: 'chkAppDekanEntryCreateTransferInput', NAME: 'chkAppDekanEntryCreateTransferInput'},						
								// {boxLabel: 'BAKU', id: 'chkAppBAKUEntryCreateTransferInput', NAME: 'chkAppBAKUEntryCreateTransferInput'},						
								// {boxLabel: 'WR KU', id: 'chkAppWR2EntryCreateTransferInput', NAME: 'chkAppWR2EntryCreateTransferInput'}					
							// ]
						// }
						
					// ]
				// },
				// {
					// xtype: 'displayfield',
					// id: 'dspTotDetailJumEntryCreateTransferInput',
					// value: 'Total Biaya Rp. ',
					// style: 'padding-left: 50px;font-weight: bold;font-size: 14px;'					
				// },
				// {
					// xtype: 'textfield',
					// id: 'txtTotDetailJumEntryCreateTransferInput',
					// readOnly: true,
					// width: 198,
					// style: 'font-weight: bold;text-align: right;'
				// }
			// ]
		// }
	// );
	
	winFormEntryCreateTransferInput = new Ext.Window(
		{
			id: 'winFormEntryCreateTransferInput',
			title: 'Create',
			closeAction: 'destroy',
			width: 800,
			height: 400, 			
			resizable: false,
			layout: 'border',
			iconCls: '',
			modal: true,
			items: 
			[
				getFormHeaderCreateTransferInput(),
				getGridDetailEntryCreateTransferInput()
				//,				pnlTotDetailJumEntryCreateTransferInput
			],
			listeners:
			{
				'beforedestroy': function()
				{ 
					RefreshDataGListCreateTransferInput(getCriteriaGListCreateTransferInput()); 
					rowselectGListCreateTransferInput = undefined;
				}
			}
		}
	);
	
	winFormEntryCreateTransferInput.show();
	
	if(rowdata !== undefined)
	{
		InitDataEntryCreateTransferInput(rowdata);
	}
	else
	{
		AddNewEntryCreateTransferInput();
	}
}

function getFormHeaderCreateTransferInput()
{
	
	var pnlFormEntryCreateTransferInput = new Ext.FormPanel
	(
		{
			id: 'pnlFormEntryCreateTransferInput',
			border: false,
			region: 'north',
			height: 150,			
			items:
			[
				{
					xtype: 'fieldset',
					layout: 'form',
					style: 'margin: 5px;',					
					defaults: { labelWidth: 120 },
					items:
					[
						{
							xtype: 'compositefield',
							fieldLabel: 'Nomor',
							defaults: { anchor: '100%', flex: 1 },
							items: 
							[
								{
									xtype: 'textfield',
									id: 'txtNoEntryCreateTransferInput',
									width: 120
								},
								{ xtype: 'label', cls: 'left-label', width: 80, text: 'Tanggal : ' },
								{
									xtype: 'datefield',
									id: 'dtpTglEntryCreateTransferInput',
									format: 'd/M/Y',
									readOnly:true,
									width : 100,
									value: now.format('d/M/Y')
								}
							]
						},
						
						
						{
							xtype: 'compositefield',
							fieldLabel: 'From Store',
							defaults: { anchor: '100%', flex: 1 },
							items: 
							[
								mcboStoreFromCreateTransferInput(),
								
								{ xtype: 'label', cls: 'left-label', forId: '', text: 'S.d : ', width: 40 },
								mcboStoreTOCreateTransferInput()
							]
						},
						
						{
							xtype: 'textarea',
							id: 'txtaKetEntryCreateTransferInput',
							fieldLabel: 'Note',
							anchor: '100%',
							height: 40
						}
						//,
						// {
							// xtype: 'compositefield',
							// fieldLabel: 'Program (KUPPA)',
							// defaults: { anchor: '100%', flex: 1 },
							// items: 
							// [
								// {
									// xtype: 'textfield',
									// id: 'txtRKATEntryCreateTransferInput',
									// readOnly: true,
									// width: 60,
									// hidden: true
								// },
								// {
									// xtype: 'textfield',
									// id: 'txtJnsRKATEntryCreateTransferInput',
									// readOnly: true,
									// width: 60,
									// hidden: true
								// },
								// {
									// xtype: 'textfield',
									// id: 'txtNoProgEntryCreateTransferInput',
									// readOnly: true,
									// width: 60
								// },								
								// {
									// xtype: 'textfield',
									// id: 'txtNmProgEntryCreateTransferInput',
									// readOnly: true
								// },
								// { xtype: 'label', cls: 'left-label', forId: '', text: 'Prioritas : ', width: 80 },
								// {
									// xtype: 'numberfield',
									// id: 'numPriorEntryCreateTransferInput',
									// readOnly: true,
									// style: 'text-align: right',
									// width: 30
								// }
							// ]
						// },
						// {
							// xtype: 'textarea',
							// id: 'txtaKegEntryCreateTransferInput',
							// fieldLabel: 'Kegiatan',
							// readOnly: true,
							// height: 40,
							// anchor: '100%'
						// },
						
					]
				}
			],
			tbar:
			[
				{
					xtype: 'button',
					id: 'btnAddEntryCreateTransferInput',
					iconCls: 'add',
					text: 'Tambah',
					handler: function(){ AddNewEntryCreateTransferInput(); }
				},
				{
					xtype: 'button',
					id: 'btnSaveEntryCreateTransferInput',
					iconCls: 'save',
					text: 'Simpan',
					handler: function()
					{
						SaveDataEntryCreateTransferInput(false);
					}
				},
				{
					xtype: 'button',
					id: 'btnSaveExitEntryCreateTransferInput',
					iconCls: 'saveexit',
					text: 'Simpan & Keluar',
					handler: function()
					{
						SaveDataEntryCreateTransferInput(true);
					}
				},
				{
					xtype: 'button',
					id: 'btnDelEntryCreateTransferInput',
					iconCls: 'remove',
					text: 'Hapus',
					handler: function()
					{
						HapusEntryEntryCreateTransferInput()
					}
				}
				//,
				
				// { xtype: 'tbseparator' },
				// {
					// xtype: 'button',
					// id: 'btnApproveEntryCreateTransferInput',
					// iconCls: 'approve',
					// text: 'Approve',
					// handler: function()
					// {
						// if(ValidasiAppEntryCreateTransferInput() == 1)
						// {
							// ApproveEntryCreateTransferInput()
						// }
					// }
				// },
				// { xtype: 'tbfill'},
				// {
					// xtype: 'button',
					// id: 'btnPrintEntryCreateTransferInput',
					// iconCls: 'print',
					// text: 'Cetak',
					// handler: function()
					// {
						// if(Validasi_CreateTransferInput2() == 1)
						// {
							// var criteria = GetCriteria_CreateTransferInput2();
							// ShowReport('', '011502', criteria);
						// }
					// }
				// }
			]
		}
	);
	
	return pnlFormEntryCreateTransferInput;
}

function mcboStoreFromCreateTransferInput()
{
	var Field = ['STRCOD', 'STORE','UNITKERJA'];
	var dscboStoreFromCreateTransferInput = new WebApp.DataStore({ fields: Field });
	dscboStoreFromCreateTransferInput.load
	(
		{ 
			params: 
			{ 
				Skip: 0, 
				Take: 250, 
				Sort: 'STRCOD', 
				Sortdir: 'ASC', 
				target: 'Store',
				param: ""
			} 
		}
	);		

  var cboStoreFromCreateTransferInput = new Ext.form.ComboBox
	(
		{
			id: 'cboStoreFromCreateTransferInput',
			typeAhead: true,
			triggerAction: 'all',
			lazyRender:true,
			mode: 'local',
			//emptyText: ' Unit Kerja...',
			fieldLabel: 'Store',			
			align: 'right',
			//anchor: '100%',
			width:130,
			store: dscboStoreFromCreateTransferInput,
			valueField: 'STRCOD',
			displayField: 'STORE',
			listeners:  
			{
				'select': function(a,b,c)
				{   
					selectcboStoreFromCreateTransferInput = b.data.STRCOD ;
				} 
			}
		}
	);	
	
	return cboStoreFromCreateTransferInput;
}


function mcboStoreTOCreateTransferInput()
{
	var Field = ['STRCOD', 'STORE','UNITKERJA'];
	var dscboStoreToCreateTransferInput = new WebApp.DataStore({ fields: Field });
	dscboStoreToCreateTransferInput.load
	(
		{ 
			params: 
			{ 
				Skip: 0, 
				Take: 250, 
				Sort: 'STRCOD', 
				Sortdir: 'ASC', 
				target: 'Store',
				param: ""
			} 
		}
	);		

  var cboStoreToCreateTransferInput = new Ext.form.ComboBox
	(
		{
			id: 'cboStoreToCreateTransferInput',
			typeAhead: true,
			triggerAction: 'all',
			lazyRender:true,
			mode: 'local',
			//emptyText: ' Unit Kerja...',
			fieldLabel: 'Store',			
			align: 'right',
			//anchor: '100%',
			width:130,
			store: dscboStoreToCreateTransferInput,
			valueField: 'STRCOD',
			displayField: 'STORE',
			listeners:  
			{
				'select': function(a,b,c)
				{   
					selectcboStoreToCreateTransferInput = b.data.STRCOD ;
				} 
			}
		}
	);	
	
	return cboStoreToCreateTransferInput;
}


function AddNewEntryCreateTransferInput()
{
	vAddNewDataEntryCreateTransferInput = true;
	Ext.getCmp('txtNoEntryCreateTransferInput').setValue('');
	Ext.getCmp('dtpTglEntryCreateTransferInput').setValue(now.format('d/M/Y'));
//	Ext.getCmp('chkApprovedEntryCreateTransferInput').setValue(false);	
	Ext.getCmp('txtaKetEntryCreateTransferInput').setValue('');
//	Ext.getCmp('txtRKATEntryCreateTransferInput').setValue('');
	//Ext.getCmp('txtJnsRKATEntryCreateTransferInput').setValue('');
	//Ext.getCmp('txtNoProgEntryCreateTransferInput').setValue('');
	//Ext.getCmp('txtNmProgEntryCreateTransferInput').setValue('');
	//Ext.getCmp('numPriorEntryCreateTransferInput').setValue('');
	//Ext.getCmp('txtaKegEntryCreateTransferInput').setValue('');
	//Ext.getCmp('txtJumBiayaEntryCreateTransferInput').setValue(0);
	//Ext.getCmp('txtTotDetailJumEntryCreateTransferInput').setValue(0);
//	Ext.getCmp('cboStoreFromCreateTransferInput').reset();
	//Ext.getCmp('chkAppKajurEntryCreateTransferInput').setValue(false);
//	Ext.getCmp('chkAppDekanEntryCreateTransferInput').setValue(false);
	//Ext.getCmp('chkAppBAKUEntryCreateTransferInput').setValue(false);
	//Ext.getCmp('chkAppWR2EntryCreateTransferInput').setValue(false);
	//Ext.getCmp('rdJalurKBS').setValue("1");
	//Ext.getCmp('txtApproverEntrySP3D').setValue('');
	//Ext.getCmp('txtJabatanEntrySP3D').setValue('');
	selectcboStoreFromCreateTransferInput = undefined;

	dsGridDetailEntryCreateTransferInput.removeAll();
}

function InitDataEntryCreateTransferInput(rowdata)
{
	vAddNewDataEntryCreateTransferInput = false;	
	Ext.getCmp('txtNoEntryCreateTransferInput').setValue(rowdata.NO_SP3D);
	Ext.getCmp('dtpTglEntryCreateTransferInput').setValue(ShowDate(rowdata.TGL_SP3D));	
	dtTglSP3DAsal = ShowDate(rowdata.TGL_SP3D);
	Ext.getCmp('txtaKetEntryCreateTransferInput').setValue(rowdata.KETERANGAN);
	Ext.getCmp('txtRKATEntryCreateTransferInput').setValue(rowdata.RKAT);
	Ext.getCmp('txtJnsRKATEntryCreateTransferInput').setValue(rowdata.KD_JNS_RKAT_JRKA);
	Ext.getCmp('txtNoProgEntryCreateTransferInput').setValue(rowdata.NO_PROGRAM_PROG);
	Ext.getCmp('txtNmProgEntryCreateTransferInput').setValue(rowdata.NAMA_PROGRAM_PROG);
	Ext.getCmp('numPriorEntryCreateTransferInput').setValue(rowdata.PRIORITAS);
	Ext.getCmp('txtaKegEntryCreateTransferInput').setValue(rowdata.KEGIATAN);
	//JML_ANGGARAN
	
	Ext.getCmp('txtJumBiayaEntryCreateTransferInput').setValue(formatCurrency(rowdata.JML_ANGGARAN));
	
	Ext.getCmp('cboStoreFromCreateTransferInput').setValue(rowdata.UNITKERJA);
	selectcboStoreFromCreateTransferInput = rowdata.KD_UNIT_KERJA;	
	if(rowdata.RKAT == "Pengembangan")
	{
		
		RefreshDataGridDetail1EntryCreateTransferInput(getCriteriaGridDetailEntryCreateTransferInput());
	}
	else if (rowdata.RKAT == "Rutin")
	{
		RefreshDataGridDetail2EntryCreateTransferInput(getCriteriaGridDetailEntryCreateTransferInput());
	}else
	{
	RefreshDataGridDetail3EntryCreateTransferInput(getCriteriaGridDetailEntryCreateTransferInput());
	}
	Ext.getCmp('chkAppKajurEntryCreateTransferInput').setValue(rowdata.APP_LEVEL_1);
	Ext.getCmp('chkAppDekanEntryCreateTransferInput').setValue(rowdata.APP_LEVEL_2);
	Ext.getCmp('chkAppBAKUEntryCreateTransferInput').setValue(rowdata.APP_LEVEL_3);
	Ext.getCmp('chkAppWR2EntryCreateTransferInput').setValue(rowdata.APP_LEVEL_4);
	
	/*if (rowdata.IS_JALUR==1)
	{
		Ext.getCmp('rdJalurKBS').setValue(true);
		Ext.getCmp('rdJalurBPK').setValue(false);
	}
	else
	{
		Ext.getCmp('rdJalurKBS').setValue(false);
		Ext.getCmp('rdJalurBPK').setValue(true);
	}*/
	
	CheckDetailApprovedEntryCreateTransferInput();
}

function HapusEntryEntryCreateTransferInput()
{	
	Ext.Msg.show
	(
		{
			title:'Hapus Data',
			 msg: "Akan menghapus data?" ,
			buttons: Ext.MessageBox.YESNO,
			width:300,
			fn: function (btn)
			{					
				if (btn =='yes')
				{
					Ext.Ajax.request
					(
						{
							url: "./Datapool.mvc/DeleteDataObj",
							params: getParamSaveEntryCreateTransferInput(),
							success: function(o)
							{
								var cst = Ext.decode(o.responseText);
								if (cst.success === true)
								{
									ShowPesanInfo_CreateTransferInputAll('Data berhasil dihapus','Hapus Data');
									// RefreshDataGListEntryCreateTransferInput(getCriteriaGListEntryCreateTransferInput());
									AddNewEntryCreateTransferInput()
								}
								else if (cst.success === false && cst.pesan===0)
								{
									ShowPesanWarning('Data tidak berhasil dihapus '  + cst.pesan ,'Hapus Data');
								}
								else
								{
									ShowPesanError('Data tidak berhasil dihapus '  + cst.pesan ,'Hapus Data');
								}
							}
						}
					)//end Ajax.request
				} // end if btn yes
			}// end fn
		}
	)//end msg.show
    
}

function SaveDataEntryCreateTransferInput(isSaveExit)
{	
	if(ValidasiSaveEntryCreateTransferInput() == 1)
	{
		if(vAddNewDataEntryCreateTransferInput)
		{
			Ext.Ajax.request
			(
				{
					url: "./Datapool.mvc/CreateDataObj",
					params: getParamSaveEntryCreateTransferInput(),
					success: function(o) 
					{
						var cst = Ext.decode(o.responseText);
						if (cst.success === true) 
						{
							ShowPesanInfo_CreateTransferInputAll('Data berhasil disimpan.', 'Simpan Data');														
							Ext.getCmp('txtNoEntryCreateTransferInput').setValue(cst.nosp3d);
							if(Ext.getCmp('txtRKATEntryCreateTransferInput').getValue() == "Pengembangan")
							{								
								RefreshDataGridDetail1EntryCreateTransferInput(getCriteriaGridDetailEntryCreateTransferInput());
							}
							else if (Ext.getCmp('txtRKATEntryCreateTransferInput').getValue() == "Rutin")
							{
								RefreshDataGridDetail2EntryCreateTransferInput(getCriteriaGridDetailEntryCreateTransferInput());
							}else
							{
							RefreshDataGridDetail3EntryCreateTransferInput(getCriteriaGridDetailEntryCreateTransferInput());
							}

							if(isSaveExit)
							{ 
								winFormEntryCreateTransferInput.close(); 
							}
						}
						else if (cst.success === false && cst.pesan === 0) 
						{
							ShowPesanWarning('Data tidak berhasil disimpan, data tersebut sudah ada', 'Simpan Data');
						}
						else 
						{
							ShowPesanError('Data tidak berhasil disimpan, Error : ' + cst.pesan, 'Simpan Data');
						}
					}
				}
			);
		}
		else
		{
			Ext.Ajax.request
			(
				{
					url: "./Datapool.mvc/UpdateDataObj",
					params: getParamSaveEntryCreateTransferInput(),
					success: function(o) 
					{
						var cst = Ext.decode(o.responseText);
						if (cst.success === true) 
						{
							ShowPesanInfo_CreateTransferInputAll('Data berhasil di-edit.', 'Edit Data');
							if(isSaveExit){ winFormEntryCreateTransferInput.close(); }
						}
						else if (cst.success === false && cst.pesan === 0) 
						{
							ShowPesanWarning('Data tidak berhasil di-edit, data tersebut belum ada', 'Edit Data');
						}
						else 
						{
							ShowPesanError('Data tidak berhasil di-edit, Error : ' + cst.pesan, 'Edit Data');
						}
					}
				}
			);
		}
	}
}

function ApproveEntryCreateTransferInput() 
{
	Ext.Msg.show
	(
		{
			title: 'Approve',
			msg: 'Apakah Transaksi Ini Akan DiApprove ?',
			buttons: Ext.MessageBox.YESNO,
			fn: function(btn) 
			{
				if (btn == 'yes') 
				{							
					Ext.Ajax.request
					({ url: "./Datapool.mvc/UpdateDataObj",
						params: getParamAppEntryCreateTransferInput(),
						success: function(o) 
						{
							var cst = o.responseText;
							if (cst == '{"success":true}') 
							{
								ShowPesanInfo_CreateTransferInputAll('Data berhasil diapprove','Approve Data');                
							}
							else
							{ 
								ShowPesanError('Data gagal diapprove','Approve Data'); 
							}
						}
					})    
				}
			},
			icon: Ext.MessageBox.QUESTION
		}
	);
};

function ValidasiSaveEntryCreateTransferInput()
{
	var valid = 1;
	
	/* if(Ext.getCmp('txtNoEntryCreateTransferInput').getValue() == "")
	{
		ShowPesanWarning("No SP3D belum diisi.", "Simpan Data");
		valid -= 1;
	} 
	if (Ext.getCmp('rdJalurKBS').getValue() === false && 
		Ext.getCmp('rdJalurBPK').getValue() === false )
	{
		
		if (mBolHapus === false)
		{
		x=0;
			ShowPesanWarning_viDtPgw("Jalur Belum Terisi",modul);
		}
	}	
	*/
	if(Ext.getCmp('dtpTglEntryCreateTransferInput').getValue() == "")
	{
		ShowPesanWarning("Tanggal SP3D belum diisi.", "Simpan Data");
		valid -= 1;
	}
	
	if(selectcboStoreFromCreateTransferInput === undefined)
	{
		ShowPesanWarning("Unit kerja belum dipilih..", "Simpan Data");
		valid -= 1;
	}
	
	if(Ext.getCmp('numPriorEntryCreateTransferInput').getValue() == "" || Ext.getCmp('txtaKegEntryCreateTransferInput').getValue() == "")
	{
		ShowPesanWarning("Data RKAT belum dipilih.", "Simpan Data");
		valid -= 1;
	}
	
	if(dsGridDetailEntryCreateTransferInput.getCount() <= 0)
	{
		ShowPesanWarning("Transaksi harus memiliki detail.", "Simpan Data");
		valid -= 1;
	}
	
	return valid;
}

function ValidasiAppEntryCreateTransferInput()
{
	var valid = 1;
	
	if(Ext.getCmp('txtNoEntryCreateTransferInput').getValue() == "")
	{
		ShowPesanWarning("No SP3D belum diisi.", "Simpan Data");
		valid = 0;
	}
	return valid;
}

function getParamSaveEntryCreateTransferInput()
{
	var jalurTransaksi;
	
	/*if (Ext.getCmp('rdJalurKBS').getValue()===true)
	{
		jalurTransaksi=1; //KBS
	}
	else
	{
		jalurTransaksi=2; //BPK
	}
	*/
	var params = 
	{
		Table: 'viSP3D',
		is_app:0,
		IS_DETAIL:0,
		IS_JALUR:jalurTransaksi,
		nosp3d: Ext.getCmp('txtNoEntryCreateTransferInput').getValue(),
		tglsp3d: ShowDate(Ext.getCmp('dtpTglEntryCreateTransferInput').getValue()),
		tglsp3dasal: dtTglSP3DAsal === undefined ? ShowDate(Ext.getCmp('dtpTglEntryCreateTransferInput').getValue()) : ShowDate(dtTglSP3DAsal),
		unit: selectcboStoreFromCreateTransferInput,
		ket: Ext.getCmp('txtaKetEntryCreateTransferInput').getValue(),
		rkat: Ext.getCmp('txtRKATEntryCreateTransferInput').getValue(),
		jnsrkat: Ext.getCmp('txtJnsRKATEntryCreateTransferInput').getValue(),
		noprog: Ext.getCmp('txtNoProgEntryCreateTransferInput').getValue(),
		prior: Ext.getCmp('numPriorEntryCreateTransferInput').getValue(),
		jum: getNumber(Ext.getCmp('txtTotDetailJumEntryCreateTransferInput').getValue()),
		
		lists: getArrDetailEntryCreateTransferInput(),
		nrow: dsGridDetailEntryCreateTransferInput.getCount(),
		nfield: 12
	};
	
	return params;
}

function getParamDeldetailCreateTransferInput()
{
	var params = 
	{
		Table: 'viSP3D',		
		IS_DETAIL:1,	
		rkat: Ext.getCmp('txtRKATEntryCreateTransferInput').getValue(),
		TAHUN_ANGGARAN_TA: ShowDate(Ext.getCmp('dtpTglEntryCreateTransferInput').getValue()),
		unit: selectcboStoreFromCreateTransferInput,
		nosp3d: Ext.getCmp('txtNoEntryCreateTransferInput').getValue(),
		tglsp3d: ShowDate(Ext.getCmp('dtpTglEntryCreateTransferInput').getValue()),
		NO_PROGRAM_PROG: Ext.getCmp('txtNoProgEntryCreateTransferInput').getValue(),
		PRIORITAS_SP3D: Ext.getCmp('numPriorEntryCreateTransferInput').getValue(),
		URUT:dsGridDetailEntryCreateTransferInput.data.items[CurrentRowGridDetailEntryCreateTransferInput.row].data.LINE		
	};	
	return params;
}

function getParamAppEntryCreateTransferInput()
{
	var params = 
	{
		Table: 'viSP3D',
		nosp3d: Ext.getCmp('txtNoEntryCreateTransferInput').getValue(),
		tglsp3d: ShowDate(Ext.getCmp('dtpTglEntryCreateTransferInput').getValue()),
		tglsp3dasal: dtTglSP3DAsal === undefined ? ShowDate(Ext.getCmp('dtpTglEntryCreateTransferInput').getValue()) : ShowDate(dtTglSP3DAsal),
		unit: selectcboStoreFromCreateTransferInput,
		ket: Ext.getCmp('txtaKetEntryCreateTransferInput').getValue(),
		rkat: Ext.getCmp('txtRKATEntryCreateTransferInput').getValue(),
		jnsrkat: Ext.getCmp('txtJnsRKATEntryCreateTransferInput').getValue(),
		noprog: Ext.getCmp('txtNoProgEntryCreateTransferInput').getValue(),
		jum: getNumber(Ext.getCmp('txtTotDetailJumEntryCreateTransferInput').getValue()),
		prior: Ext.getCmp('numPriorEntryCreateTransferInput').getValue(),
		is_app:1
	};
	
	return params;
}

function getArrDetailEntryCreateTransferInput()
{
	var x = "";
	var y = "";
	var	z = "@@##$$@@";
	
	if(dsGridDetailEntryCreateTransferInput.getCount() > 0)
	{
		for(var i=0; i<dsGridDetailEntryCreateTransferInput.getCount(); i++)
		{
			y = "col_line=" + dsGridDetailEntryCreateTransferInput.data.items[i].data.LINE;
			y += z + "col_thn=" + dsGridDetailEntryCreateTransferInput.data.items[i].data.TAHUN_ANGGARAN_TA;
			y += z + "col_unit=" + dsGridDetailEntryCreateTransferInput.data.items[i].data.KD_UNIT_KERJA;
			y += z + "col_jnsrkat=" + dsGridDetailEntryCreateTransferInput.data.items[i].data.KD_JNS_RKAT_JRKA;
			y += z + "col_noprog=" + dsGridDetailEntryCreateTransferInput.data.items[i].data.NO_PROGRAM_PROG;
			y += z + "col_prior=" + dsGridDetailEntryCreateTransferInput.data.items[i].data.PRIORITAS;
			y += z + "col_nosp3d=" + dsGridDetailEntryCreateTransferInput.data.items[i].data.NO_SP3D;
			y += z + "col_tglsp3d=" + ShowDate(dsGridDetailEntryCreateTransferInput.data.items[i].data.TGL_SP3D);
			y += z + "col_akun=" + dsGridDetailEntryCreateTransferInput.data.items[i].data.ACCOUNT;
			y += z + "col_desc=" + dsGridDetailEntryCreateTransferInput.data.items[i].data.DESKRIPSI;
			y += z + "col_value=" + dsGridDetailEntryCreateTransferInput.data.items[i].data.VALUE;
			y += z + "col_posted=" + dsGridDetailEntryCreateTransferInput.data.items[i].data.POSTED;
			
			if(i == dsGridDetailEntryCreateTransferInput.getCount() - 1)
			{
				x += y;
			}
			else
			{
				x += y + "##[[]]##";
			}
		}
	}
	
	return x;
}

function CheckDetailApprovedEntryCreateTransferInput()
{
	var x = 0;
	if(dsGridDetailEntryCreateTransferInput.getCount() > 0)
	{
		for(var i=0;i<dsGridDetailEntryCreateTransferInput.getCOunt();i++)
		{
			x += 1;
		}
	}
	
	if(x === dsGridDetailEntryCreateTransferInput.getCount())
	{
		Ext.getCmp('chkApprovedEntryCreateTransferInput').setValue(true);	
	}
	else
	{
		Ext.getCmp('chkApprovedEntryCreateTransferInput').setValue(false);	
	}
}

function getGridDetailEntryCreateTransferInput()
{
	
	var Fields = [
		'TAHUN_ANGGARAN_TA',
		'KD_UNIT_KERJA',
		'KD_JNS_RKAT_JRKA',
		'NO_PROGRAM_PROG',
		'PRIORITAS',
		'NO_SP3D',
		'TGL_SP3D',
		'LINE',
		'ACCOUNT',
		'NAME',
		'DESKRIPSI',
		'VALUE',
		'POSTED',
		'DESKRIPSI'
	];
	dsGridDetailEntryCreateTransferInput = new WebApp.DataStore({ fields: Fields });	
	
	var grdDetailEntryCreateTransferInput = new Ext.grid.EditorGridPanel(
		{
			id: 'grdDetailEntryCreateTransferInput',
			border: false,
			region: 'center',
			anchor: '100% 60%',
			store: dsGridDetailEntryCreateTransferInput,
			autoScroll: true,
			viewConfig: { forceFit: true },
			sm: new Ext.grid.RowSelectionModel(
				{
					singleSelect: true,
					listeners:
					{
						'rowselect': function(sm, row, rec)
						{
							rowselectGridDetailEntryCreateTransferInput = dsGridDetailEntryCreateTransferInput.getAt(row);
							CurrentRowGridDetailEntryCreateTransferInput.row = row;
							CurrentRowGridDetailEntryCreateTransferInput.data = rowselectGridDetailEntryCreateTransferInput.data;
						}
					}
				}
			),
			cm: new Ext.grid.ColumnModel(
				[
					new Ext.grid.RowNumberer(),
					{
						xtype: 'gridcolumn',
						id: 'col_noakun_gldetail',
						dataIndex: 'ACCOUNT',
						header: 'Barcode',
						width: 50
						/*,
						editor: new Ext.form.TextField(
							{
								id: 'fcol_noakun_detCreateTransferInput',
								enableKeyEvents: true,
								listeners:
								{
									'specialkey': function()
									{
										if(Ext.EventObject.getKey() === 13)
										{
											alert(this.getValue());
										}
									}
								}
							}
						)*/
					},
					{
						xtype: 'gridcolumn',
						id: 'col_nmakun_gldetail',
						dataIndex: 'NAME',
						header: 'Nama Barang'/*,
						editor: new Ext.form.TextField(
							{
								id: 'fcol_nmakun_detCreateTransferInput',
								enableKeyEvents: true,
								listeners:
								{
									'specialkey': function()
									{
										if(Ext.EventObject.getKey() === 13)
										{
											alert(this.getValue());
										}
									}
								}
							}
						)*/
					},
					{
						xtype: 'gridcolumn',
						id: 'col_des_gldetail',
						dataIndex: 'DESKRIPSI',
						header: 'Deskripsi',
						editor: new Ext.form.TextField(
							{
								id: 'fcol_des_detCreateTransferInput'								
							}
						)
					},
					/* {
						xtype: 'gridcolumn',
						id: 'col_ket_gldetail',
						dataIndex: 'KETERANGAN',
						header: 'Keterangan',
						editor: new Ext.form.TextField(
							{
								id: 'fcol_ket_detCreateTransferInput'								
							}
						)
					}, */
					
					{
						xtype: 'gridcolumn',
						id: 'col_jum_gldetail',
						dataIndex: 'VALUE',
						header: 'Jumlah',
						renderer: function(v, params, record)
						{
							var str = "<div style='white-space:normal; padding: 2px;text-align: right;'>" + formatCurrency(record.data.VALUE) + "</div>";
							return str;
						},
						editor: new Ext.form.TextField(
							{
								id: 'fcol_jum_detCreateTransferInput',
								style: 'text-align: right;',
								enableKeyEvents: true,
								listeners:
								{
									'specialkey': function()
									{
										if(Ext.EventObject.getKey() === 13)
										{
											CalcTotalDetailEntryCreateTransferInput();
										}
									},
									'blur' : function(){
										CalcTotalDetailEntryCreateTransferInput();
									}
								}
							}
						)
					}
				]
			),
			tbar:
			[
				 {
					xtype: 'button',
					id: 'btnAddRowDetailEntryCreateTransferInput',
					iconCls: 'add',
					text: 'Tambah Baris',
					handler: function(){ TambahBarisDetailEntryCreateTransferInput(); }
				}, 
				{
					xtype: 'button',
					id: 'btnDelRowDetailEntryCreateTransferInput',
					iconCls: 'remove',
					text: 'Hapus Baris',
					handler: function(){ HapusBarisDetailEntryCreateTransferInput(); }
				}
			],
			listeners:
			{
				'afterrender': function()
				{
					this.store.on("load",
						function()
						{
							CalcTotalDetailEntryCreateTransferInput()
						}
					);
					
					this.store.on("datachanged",
						function()
						{
							CalcTotalDetailEntryCreateTransferInput()
						}
					);
				}
			}
		}
	);
	
	return grdDetailEntryCreateTransferInput;
}

function RefreshDataGridDetail1EntryCreateTransferInput(criteria)
{
	dsGridDetailEntryCreateTransferInput.load
	(
		{ 
			params: 
			{ 
				Skip: 0, 
				Take: 1000, 
				Sort: '', 
				Sortdir: 'ASC', 
				target: 'viListDetailSP3DK',
				param: criteria
			} 
		}
	);
	
	return dsGridDetailEntryCreateTransferInput;
}

function RefreshDataGridDetail3EntryCreateTransferInput(criteria)
{
	dsGridDetailEntryCreateTransferInput.load
	(
		{ 
			params: 
			{ 
				Skip: 0, 
				Take: 1000, 
				Sort: '', 
				Sortdir: 'ASC', 
				target: 'viewListDetailSP3DO',
				param: criteria
			} 
		}
	);
	
	return dsGridDetailEntryCreateTransferInput;
}

function RefreshDataGridDetail2EntryCreateTransferInput(criteria)
{
	dsGridDetailEntryCreateTransferInput.load
	(
		{ 
			params: 
			{ 
				Skip: 0, 
				Take: 1000, 
				Sort: '', 
				Sortdir: 'ASC', 
				target: 'viListDetailSP3DR',
				param: criteria
			} 
		}
	);
	
	return dsGridDetailEntryCreateTransferInput;
}

function getCriteriaGridDetailEntryCreateTransferInput()
{
	var strKriteria = "";
	
	if(Ext.getCmp('txtNoEntryCreateTransferInput').getValue() !== "")
	{
	   
		if(strKriteria !== "")
		{
			strKriteria += " and SRKD.NO_SP3D_RKAT='" + Ext.getCmp('txtNoEntryCreateTransferInput').getValue()  + "'";
		}
		else
		{
			strKriteria += " Where SRKD.NO_SP3D_RKAT='" + Ext.getCmp('txtNoEntryCreateTransferInput').getValue()  + "'";
		}
	}	
	if(Ext.getCmp('dtpTglEntryCreateTransferInput').getValue() !== "")
	{
		if(strKriteria !== "")
		{
			strKriteria += " and SRKD.TGL_SP3D_RKAT='" + ShowDate(Ext.getCmp('dtpTglEntryCreateTransferInput').getValue())  + "'";
		}
		else
		{
			strKriteria += " Where SRKD.TGL_SP3D_RKAT='" + ShowDate(Ext.getCmp('dtpTglEntryCreateTransferInput').getValue())  + "'";
		}		
	}		
	return strKriteria;
}

function CalcTotalDetailEntryCreateTransferInput()
{
	var total = 0;
	
	if(dsGridDetailEntryCreateTransferInput.getCount() > 0)
	{
		for(var i=0;i<dsGridDetailEntryCreateTransferInput.getCount();i++)
		{
			// total += getNumber(dsGridDetailEntryCreateTransferInput.data.items[i].data.VALUE);
			total += dsGridDetailEntryCreateTransferInput.data.items[i].data.VALUE;
		}
	}	
	Ext.getCmp('txtTotDetailJumEntryCreateTransferInput').setValue(formatCurrency(total));
	
}

function TambahBarisDetailEntryCreateTransferInput()
{
	// var x = true;
	// if(dsGridDetailEntryCreateTransferInput.getCount() > 0)
	// {		
		// if(dsGridDetailEntryCreateTransferInput.data.items[dsGridDetailEntryCreateTransferInput.getCount() - 1].data.ACCOUNT == "")
		// {
			// x = false;
		// }
	// }
	
	//if(x)
	//{
		var p = new mRecordDetailEntryCreateTransferInput(
			{
				TAHUN_ANGGARAN_TA: '',
				KD_UNIT_KERJA: '',
				KD_JNS_RKAT_JRKA: '',
				NO_PROGRAM_PROG: '',
				PRIORITAS: '',
				NO_SP3D: '',
				TGL_SP3D: '',
				LINE: 0,
				ACCOUNT: '',
				NAME: '',
				DESKRIPSI: '',
				VALUE: 0,
				POSTED: 0
			}
		);
		
		dsGridDetailEntryCreateTransferInput.insert(dsGridDetailEntryCreateTransferInput.getCount(), p);
		rowselectGridDetailEntryCreateTransferInput = dsGridDetailEntryCreateTransferInput.getAt(dsGridDetailEntryCreateTransferInput.getCount());
		CurrentRowGridDetailEntryCreateTransferInput.row = dsGridDetailEntryCreateTransferInput.getCount();
		CurrentRowGridDetailEntryCreateTransferInput.data = rowselectGridDetailEntryCreateTransferInput
	//}
}

function HapusBarisDetailEntryCreateTransferInput()
{		
	var fn_HapusDetail = function(btn)
	{
		
		if(btn == "yes")
		{
			if(dsGridDetailEntryCreateTransferInput.data.items[CurrentRowGridDetailEntryCreateTransferInput.row].data.LINE == 0)
			{				
				dsGridDetailEntryCreateTransferInput.removeAt(CurrentRowGridDetailEntryCreateTransferInput.row);
				ShowPesanInfo_CreateTransferInputAll("Baris ke-" + (CurrentRowGridDetailEntryCreateTransferInput.row + 1) + " berhasil dihapus!", "Hapus Baris");
				CalcTotalDetailEntryCreateTransferInput();
			}
			else
			{			
				Ext.Ajax.request
				(
					{
						url: "./Datapool.mvc/DeleteDataObj",
						params:  getParamDeldetailCreateTransferInput(),
						success: function(o) 
						{
							var cst = Ext.decode(o.responseText);
							if (cst.success === true) 
							{
								dsGridDetailEntryCreateTransferInput.removeAt(CurrentRowGridDetailEntryCreateTransferInput.row);
								ShowPesanInfo("Baris ke-" + (CurrentRowGridDetailEntryCreateTransferInput.row + 1) + " berhasil dihapus!", "Hapus Baris");
								CalcTotalDetailEntryCreateTransferInput();
							}
							else if (cst.success === false && cst.pesan === 0 )
							{
								ShowPesanWarning('Data tidak berhasil dihapus, data tersebut belum ada','Hapus Data');
							}
							else 
							{
								ShowPesanError('Data tidak berhasil dihapus','Hapus Data');
							};
						}
					}
				);
			}
		}
	}
	if(dsGridDetailEntryCreateTransferInput !== undefined || dsGridDetailEntryCreateTransferInput.getCount() > 1)
	{
		var msg = "Hapus baris ke-" + (CurrentRowGridDetailEntryCreateTransferInput.row + 1) + " "
		ShowPesanConfirm(msg, "Hapus Baris", fn_HapusDetail);
	}	
}

function loadDetailRKATEntryCreateTransferInput(criteria)
{	
	var Fields = 
	[
		'TAHUN_ANGGARAN_TA',
		'KD_UNIT_KERJA',
		'KD_JNS_RKAT_JRKA',
		'NO_PROGRAM_PROG',
		'PRIORITAS',
		'LINE',
		'ACCOUNT',
		'NAME',
		'JUMLAH','DESKRIPSI'
	];
	var dsTmp = new WebApp.DataStore({ fields: Fields });
	var target ="";
	if (Ext.getCmp('txtRKATEntryCreateTransferInput').getValue() == "Rutin")
	{ 
	target ='viDetailRKATSP3DR' ;
	}else if (Ext.getCmp('txtRKATEntryCreateTransferInput').getValue() == "Pengembangan")
	{
	target = 'viDetailRKATSP3DK';
	}else {
	target ='viewDetailRKATSP3DO'
	};
	dsTmp.load
	(
		{
			params:
			{
			    Skip: 0,
			    Take: 1000,
			    Sort: '',
			    Sortdir: '',
			    target: target,
			    param: criteria
			}
		}
	);
	dsTmp.on
	("load",
		function(){ insertToGridDetailEntryCreateTransferInput(dsTmp); }
	);
}

function insertToGridDetailEntryCreateTransferInput(ds)
{
	if(dsGridDetailEntryCreateTransferInput.getCount > 0){ dsGridDetailEntryCreateTransferInput.removeAll(); }
	
	if(ds.getCount() > 0)
	{
		for(var i=0;i<ds.getCount();i++)
		{			
			var p = new mRecordDetailEntryCreateTransferInput
			(
				{
					// --LINE: 0,//ds.data.items[i].data.LINE,
					LINE: ds.data.items[i].data.LINE,
					TAHUN_ANGGARAN_TA: ds.data.items[i].data.TAHUN_ANGGARAN_TA,
					KD_UNIT_KERJA: ds.data.items[i].data.KD_UNIT_KERJA,
					KD_JNS_RKAT_JRKA: ds.data.items[i].data.KD_JNS_RKAT_JRKA,
					NO_PROGRAM_PROG: ds.data.items[i].data.NO_PROGRAM_PROG,
					PRIORITAS: ds.data.items[i].data.PRIORITAS,
					NO_SP3D: Ext.getCmp('txtNoEntryCreateTransferInput').getValue(),
					TGL_SP3D: Ext.getCmp('dtpTglEntryCreateTransferInput').getValue(),
					ACCOUNT: ds.data.items[i].data.ACCOUNT,
					NAME: ds.data.items[i].data.NAME,
					DESKRIPSI: ds.data.items[i].data.DESKRIPSI,
					VALUE: ds.data.items[i].data.JUMLAH,
					POSTED: 0
				}
			);			
			dsGridDetailEntryCreateTransferInput.insert(dsGridDetailEntryCreateTransferInput.getCount(), p);
		}
		
		CalcTotalDetailEntryCreateTransferInput();
	}
}

function getCriteriaDetailRKATEntryCreateTransferInput()
{
	var strKriteria = "";
	
	if(Ext.getCmp('dtpTglEntryCreateTransferInput').getValue() !== "")
	{
		var tahun = (Ext.getCmp('dtpTglEntryCreateTransferInput').getValue()).getYear() < 1900 ? 1900 + (Ext.getCmp('dtpTglEntryCreateTransferInput').getValue()).getYear() : (Ext.getCmp('dtpTglEntryCreateTransferInput').getValue()).getYear();
		if(strKriteria != "")
		{
			strKriteria += "&";
		}
		strKriteria += "tahun=" + tahun;
	}
	
	if(selectcboStoreFromCreateTransferInput !== undefined)
	{
		if(strKriteria != "")
		{
			strKriteria += "&";
		}
		strKriteria += "unit=" + selectcboStoreFromCreateTransferInput;
	}
	
	if(Ext.getCmp('txtJnsRKATEntryCreateTransferInput').getValue() !== "")
	{
		if(strKriteria != "")
		{
			strKriteria += "&";
		}
		strKriteria += "jnsrkat=" + Ext.getCmp('txtJnsRKATEntryCreateTransferInput').getValue();
	}
	
	if(Ext.getCmp('txtNoProgEntryCreateTransferInput').getValue() !== "")
	{
		if(strKriteria != "")
		{
			strKriteria += "&";
		}
		strKriteria += "noprog=" + Ext.getCmp('txtNoProgEntryCreateTransferInput').getValue();
	}
	
	if(Ext.getCmp('numPriorEntryCreateTransferInput').getValue() !== "")
	{
		if(strKriteria != "")
		{
			strKriteria += "&";
		}
		strKriteria += "prior=" + Ext.getCmp('numPriorEntryCreateTransferInput').getValue();
	}
	
	if(akun !== "" || akun !== undefined)
	{
		if(strKriteria != "")
		{
			strKriteria += "&";
		}
		strKriteria += "akun=" + akun;
	}
	
	if(jumlah !== "" || jumlah !== undefined)
	{
		if(strKriteria != "")
		{
			strKriteria += "&";
		}
		strKriteria += "jumlah=" + jumlah;
	}
	
	if(dsGridDetailEntryCreateTransferInput.getCount() > 0)
	{
		var acc = "";
		for(var i=0;i<dsGridDetailEntryCreateTransferInput.getCount();i++)
		{
			acc += "'" + dsGridDetailEntryCreateTransferInput.data.items[i].data.ACCOUNT + "'";
			if(i<dsGridDetailEntryCreateTransferInput.getCount() - 1){ acc+= ","; }
		}
		if(strKriteria != "")
		{
			strKriteria += "&";
		}
		strKriteria += "notin=" + acc;
	}
	
	return strKriteria;
}

/* Cetak SP3D */
function GetCriteria_CreateTransferInput2()
{
	var strKriteria = '';
	
	if (Ext.getCmp('txtNoEntryCreateTransferInput').getValue() != '') 
	{
		strKriteria = " Where NO_SP3D_RKAT ='" + Ext.getCmp('txtNoEntryCreateTransferInput').getValue() + "'";
	};
	
	if (Ext.getCmp('cboStoreFromCreateTransferInput').getValue() != '') 
	{
		strKriteria += " and KD_UNIT_KERJA ='" + selectcboStoreFromCreateTransferInput + "'";
	};
	
	return strKriteria;
};

function Validasi_CreateTransferInput2()
{
	var x=1;
	
	if((Ext.getCmp('txtNoEntryCreateTransferInput').getValue() == '') || 
	(Ext.getCmp('cboStoreFromCreateTransferInput').getValue() == ''))
	{
		if(Ext.getCmp('txtNoEntryCreateTransferInput').getValue() == '')
		{
			ShowPesanWarning_CreateTransferInput2('No. SP3D belum di isi','Laporan SP3D');
			x=0;
		}
		else if(Ext.getCmp('cboStoreFromCreateTransferInput').getValue() == '' )
		{
			ShowPesanWarning_CreateTransferInput2('Unit Kerja belum di isi','Laporan SP3D');
			x=0;
		}
	};
	return x;
};

function ShowPesanWarning_CreateTransferInput2(str,modul)
{
	Ext.MessageBox.show
	(
		{
		   title: modul,
		   msg:str,
		   buttons: Ext.MessageBox.OK,
		   icon: Ext.MessageBox.WARNING
		}
	);
};

function ShowPesanInfo_CreateTransferInputAll(str,modul)
{
    Ext.MessageBox.show
    (
		{
			title: modul,
			msg:str,
			buttons: Ext.MessageBox.OK,
			icon: Ext.MessageBox.INFO,
			width :250
		}
    )
}